/* eslint-disable import/first */
import { NestFactory } from '@nestjs/core'
import { ConfigService } from '@nestjs/config'
import { CrudConfigService } from '@nestjsx/crud'

CrudConfigService.load({
  params: {
    id: {
      field: 'id',
      type: 'uuid',
      primary: true
    }
  },
  routes: {
    only: [
      'getManyBase',
      'getOneBase',
      'createOneBase',
      'updateOneBase',
      'deleteOneBase',
      'recoverOneBase'
    ]
  }
})

import { AppModule } from './app.module'
import { AllExceptionFilter } from './common/all-exception.filter'
import { ValidationPipe } from './common/validation.pipe'
import { NestExpressApplication } from '@nestjs/platform-express'
import { join } from 'path'

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule)
  const configService = app.get(ConfigService)

  app.enableCors()
  app.useGlobalFilters(new AllExceptionFilter())
  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
      whitelist: true,
      stopAtFirstError: true
    })
  )
  app.useStaticAssets(join(__dirname, '..', 'public'), {
    prefix: '/public/'
  })

  await app.listen(configService.get<number>('PORT', 3000))
}
void bootstrap()
